package com.neusoft.demo.controller;

import java.io.IOException;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.neusoft.demo.po.Goods_type;
import com.neusoft.demo.service.Goods_typeService;
import com.neusoft.demo.service.UserService;

@Controller
@RequestMapping("/")
public class TestController {

	@Autowired
	UserService service;
	
	@Autowired
	Goods_typeService goods_typeService;
	
	
//	@RequestMapping(value="/test", method=RequestMethod.GET)
//	public ModelAndView Test(ModelAndView mv) {
//		List<User> user=service.findId(1);
//		System.out.println(user);
//		
//		mv.setViewName("user");
//		mv.addObject("user", user);
//		return mv;
//	}
	
	@RequestMapping("/hello")
	public ModelAndView ce(ModelAndView mv) {
		mv.setViewName("index");
		return mv;
	}
	
	@RequestMapping("/fenleiguanli")
	public ModelAndView fenleiguanli(ModelAndView mv) throws IOException {
//		Reader reader = Resources.getResourceAsReader("mybatis-config.xml");
//		SqlSessionFactory build = new SqlSessionFactoryBuilder().build(reader);
//		SqlSession session = build.openSession();
		
//		goods_typeMapper mapper = session.getMapper(goods_typeMapper.class);
//		List<goods_type> queryGoods_type = mapper.queryGoods_type();
		System.out.println("分类管理");
		List<Goods_type> queryGoods_type = goods_typeService.queryGoods_type();
		mv.setViewName("fenleiguanli");
		mv.addObject("queryGoods_type", queryGoods_type);
		System.out.println(mv);
		return mv;
	}
	
	@RequestMapping(value="/fenleiguanlixiugai")
	public ModelAndView fenyeguanlixiugai(Integer id,ModelAndView mv) {
		System.out.println(id);
		Goods_type queryGoods_typeById = goods_typeService.queryGoods_typeById(id);
		System.out.println(queryGoods_typeById);
		mv.addObject("queryGoods_typeById",queryGoods_typeById);
		mv.setViewName("fenleiguanlixiugai");
		return mv;
	}
	
	@RequestMapping(value="/fenleiguanlixiugaitijiao")
	public ModelAndView fenyeguanlixiugaitijiao(Goods_type goods_type,ModelAndView mv) {
		System.out.println(goods_type);
		goods_typeService.updateGoods_type(goods_type);
		List<Goods_type> queryGoods_type = goods_typeService.queryGoods_type();
		mv.addObject("queryGoods_type", queryGoods_type);
		mv.setViewName("fenleiguanli");
		return mv;
	}
	
	@RequestMapping("/fenleiguanlishanchu")
	public ModelAndView fenleiguanlishanchu(int id,ModelAndView mv) {
		System.out.println(id);
		goods_typeService.deleteGoods_type(id);
		List<Goods_type> queryGoods_type = goods_typeService.queryGoods_type();
		mv.addObject("queryGoods_type",queryGoods_type);
//		mv.addObject(attributeValue);
		mv.setViewName("fenleiguanli");
		return mv;
	}
	
	@RequestMapping("/fenleiguanlichaxunByLike")
	public ModelAndView fenleiguanlichaxunByLike(Goods_type goods_type,ModelAndView mv) {
		System.out.println(goods_type);
		List<Goods_type> queryGoods_typeByLike = goods_typeService.queryGoods_typeByLike(goods_type);
		mv.addObject("queryGoods_typeByLike",queryGoods_typeByLike);
		mv.setViewName("fenleiguanlichaxun");
		return mv;
	}
	
	@RequestMapping("/fenleiguanlicharu")
	public ModelAndView fenleiguanlicharu(Goods_type goods_type,ModelAndView mv) {
		System.out.println(goods_type);
		goods_typeService.addGoods_type(goods_type);
		List<Goods_type> queryGoods_type = goods_typeService.queryGoods_type();
		mv.addObject("queryGoods_type",queryGoods_type);
		mv.setViewName("fenleiguanli");
		return mv;
	}
	
//	@RequestMapping("/shangpinguanli")
//	public ModelAndView shangpinguanli(ModelAndView mv) {
//		mv.setViewName("shangpinguanli");
//		return mv;
//	}
}

